from selenium.webdriver.common.by import By

from pom.base import BaseDriver

class QuestionDetailPage(BaseDriver):
    def __init__(self, driver):
        super(QuestionDetailPage, self).__init__(driver)

    # 知识点
    _knowledge = By.XPATH, '//div[@class="el-input el-input--small el-input--suffix is-focus"]//input'

    # 选择知识点
    def select_knowledge(self, num):
        _select_knowledge = By.XPATH, '//div[@class="el-select-dropdown el-popper is-multiple"]//ul/li[int({})]'.format(num)
        ele = self.find_ele(_select_knowledge)
        self.logger.info("选择知识点")
        return ele

    # 题目标题
    _question_title = By.XPATH, '//input[@placeholder="请输入题目标题"]'

    # 题干
    _question_body = By.XPATH, '//textarea'

    # 单选题
    _radio_type = By.XPATH, '//span[@class="el-radio__label"][text()="单选题"]'

    # 多选题
    _select_type = By.XPATH, '//span[@class="el-radio__label"][text()="多选题"]'

    # 填空题
    _fill_blank_type = By.XPATH, '//span[@class="el-radio__label"][text()="填空题"]'

    # 主观题
    _subject_type = By.XPATH, '//span[@class="el-radio__label"][text()="主观题"]'

    # 设置选项
    def option(self, num):
        _option = By.XPATH, '//div[@class="option"][{}]//input[@placeholder="请输入选项内容"]'.format(int(num))
        ele = self.find_ele(*_option)
        self.logger.info("设置选项")
        return ele

    # 添加选项
    _add_option = By.XPATH, '//span[text()="添加选项"]/..'

    # 删除选项
    _delete_option = By.XPATH, '//div[@class="el-icon-delete f-fc-link"]'

    # 勾选单选答案
    def answer_radio(self, num):
        _check_radio = By.XPATH, '//div[@class="option"][{}]//span[@class="el-radio__inner"]'.format(int(num))
        ele = self.find_ele(*_check_radio)
        self.logger.info("勾选单选答案 第{}个答案".format(num))
        return ele

    # 勾选多选答案
    def answer_select(self, num):
        _check_select = By.XPATH, '//div[@class="options"]/div[{}]//span[@class="el-checkbox__inner"]'.format(int(num))
        ele = self.find_ele(*_check_select)
        self.logger.info("勾选多选答案。第{}个选项".format(num))
        return ele

    # 填空题答案
    _answer_fill = By.XPATH, '//div[@class="el-textarea el-input--medium"]//textarea'

    # 主观题答案
    _answer_subject = By.XPATH, '//textarea[@placeholder="请输入正确答案"]'

    # 上传文件
    _answer_file = By.XPATH, '//div[@class="f-m-b-20 f-ib f-m-r-20"]//input[@class="el-upload__input"]'

    # 分值设置
    _score_setting = By.XPATH, '//div[@class="el-form-item"]//input[@placeholder="请输入分值"]'

    # 其他说明
    _other_desc = By.XPATH, '//div[@class="el-input el-input--medium"]//input[@placeholder="请输入其他说明"]'

    # 上传附件
    _file = By.XPATH, '//div[@class="f-ib f-m-t-10"]//input'

    # 返回按钮
    _return_btn = By.XPATH, '//span[text()="返回"]/..'

    # 保存按钮
    _save_btn = By.XPATH, '//span[text()="保存"]/..'

    # 保存并继续按钮
    _save_continue_btn = By.XPATH, '//span[text()="保存并继续添加"]'

    #

    @property
    def save_continue_btn(self):
        ele = self.find_ele(*self._save_continue_btn)
        self.logger.info("保存并继续添加")
        return ele

    @property
    def save_btn(self):
        ele = self.find_ele(*self._save_btn)
        self.logger.info("保存按钮")
        return ele

    @property
    def return_btn(self):
        ele = self.find_ele(*self._return_btn)
        self.logger.info("返回按钮")
        return ele

    @property
    def file(self):
        ele = self.find_ele(*self._file)
        self.logger.info("上传附件")
        return ele

    @property
    def other_desc(self):
        ele = self.find_ele(*self._other_desc)
        self.logger.info("其他说明")
        return ele

    @property
    def score_setting(self):
        ele = self.find_ele(*self._score_setting)
        self.logger.info("分值设置")
        return ele

    @property
    def answer_file(self):
        ele = self.find_ele(*self._answer_file)
        self.logger.info("上传答案中的文件")
        return ele

    @property
    def answer_subject(self):
        ele = self.find_ele(*self._answer_subject)
        self.logger.info("主观题答案")
        return ele

    @property
    def answer_fill(self):
        ele = self.find_ele(*self._answer_fill)
        self.logger.info("填空题答案")
        return ele

    @property
    def delete_option(self):
        ele = self.find_ele(*self._delete_option)
        self.logger.info("删除选项")
        return ele

    @property
    def add_option(self):
        ele = self.find_ele(*self._add_option)
        self.logger.info("添加选项")
        return ele

    @property
    def subject_type(self):
        ele = self.find_ele(*self._subject_type)
        self.logger.info("主观题")
        return ele

    @property
    def fill_blank_type(self):
        ele = self.find_ele(*self._fill_blank_type)
        self.logger.info("填空题")
        return ele

    @property
    def select_type(self):
        ele = self.find_ele(*self._select_type)
        self.logger.info("多选题")
        return ele

    @property
    def radio_type(self):
        ele = self.find_ele(*self._radio_type)
        self.logger.info("单选题")
        return ele

    @property
    def question_body(self):
        ele = self.find_ele(*self._question_body)
        self.logger.info("题干内容")
        return ele

    @property
    def question_title(self):
        ele = self.find_ele(*self._question_title)
        self.logger.info("题目标题")
        return ele

    @property
    def knowlefdge(self):
        ele = self.find_ele(*self._knowledge)
        self.logger.info("知识点")
        return ele
